package com.gmaf.mas.launch.resloader;

import java.net.URL;

public class ClassLoaderResourceLoader implements ResourceLoader
{
	private static ClassLoaderResourceLoader systemLoader = new ClassLoaderResourceLoader(null);
	
	private ClassLoader classLoader = null;
	public ClassLoaderResourceLoader(ClassLoader classLoader)
	{
		this.classLoader = classLoader;
	}
	public ClassLoaderResourceLoader()
	{
		this(null);
	}
	
	public static ClassLoaderResourceLoader getSystemLoader()
	{
		return systemLoader;
	}
	@Override
	public URL getResource(String name)
	{
		if(classLoader != null)
		{
			return classLoader.getResource(name);
		}
		
		return ClassLoader.getSystemResource(name);
	}

	public String toString()
	{
		if(this.classLoader == null)
		{
			return "ClassLoaderResourceLoader: classLoader=null. java.class.path="
				+ System.getProperty("java.class.path");
		}
		return "ClassLoaderResourceLoader: classLoader=" + classLoader.toString();
	}
}
